﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using umbraco;
using umbraco.BasePages;
using umbraco.BusinessLogic;
using umbraco.interfaces;
using umbraco.controls;
using umbraco.uicontrols;
using Commerce.Common;
using umbraco.cms.businesslogic.member;


namespace CommerceForUmbraco.adminSection.commerce
{
    public partial class printOrder : System.Web.UI.Page
    {
        #region properties

        protected decimal orderSubTotal = 0;
        protected string productsArrayStr = "{}";

        // order
        private Order thisOrder;

        #endregion

        
        protected void Page_Load(object sender, EventArgs e)
        {
            string orderId = Request.QueryString.Get("o");
            thisOrder = OrderController.GetOrder(int.Parse(orderId));

            if (!IsPostBack)
            {
                orderNumber.Text = thisOrder.OrderNumber;
                orderDate.Text = thisOrder.OrderDate.ToLongDateString();
                orderStatusDisplay.Text = thisOrder.OrderStatus.ToString();

                billTo.Text = thisOrder.BillToAddress;
                Member[] thisMember = Member.GetMemberByName(thisOrder.UserName, false);
                if (thisMember.Length > 0)
                {
                    if (thisMember[0].getProperty("businessName") != null)
                    {
                        billToCompany.Text = thisMember[0].getProperty("businessName").Value.ToString();
                    }
                }
                shipTo.Text = thisOrder.ShipToAddress;
                emailAddress.Text = thisOrder.Email;
                CouponCodes.Text = thisOrder.CouponCodes;

                // Items tab
                OrderItems.Text = thisOrder.ItemsToString(true);
            }

            // Main info
            this.Pane1.Text = "Order Details";
            this.pp_ordernumber.Text = "Order Number";
            this.pp_orderdate.Text = "Order Date";
            this.pp_orderStatus.Text = "Order Status";
            this.pp_billtoCompany.Text = "Bill To Company";
            this.pp_billto.Text = "Bill To";
            this.pp_shipto.Text = "Ship To";
            this.pp_email.Text = "Email";
            this.pp_coupon.Text = "Coupon Used";

            // Items
            this.pp_order_items.Text = "Order Items";
        }
    }
}
